package com.future.mayi.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.future.mayi.R;
import com.future.mayi.activity.GoodsActivity;
import com.future.mayi.model.SortChildModel;
import com.future.mayi.model.SortParentModel;
import com.future.mayi.qsale.model.CartListModel;
import com.future.mayi.view.RadiusImageView;
import com.future.mayi.view.xrecyclerview.XRecyclerView;

import butterknife.BindView;
import butterknife.ButterKnife;


public class CategoryChildAdapter extends BaseRecyclerViewAdapter<SortChildModel> {

    public CategoryChildAdapter(Context context, XRecyclerView xRecyclerView) {
        super(context, null, xRecyclerView);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ItemViewHolder(getView(parent, R.layout.item_shop_category_child));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        ItemViewHolder viewHolder = (ItemViewHolder) holder;
        SortChildModel model = getItem(position);
        loadImg(viewHolder.vImg, model.getImage());
        viewHolder.tvName.setText(model.getGoods_name());
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SortChildModel model = getItem(position);
                GoodsActivity.startActivity(mContext, model.getGoods_id());
            }
        });

    }


    class ItemViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.item_shop_category_child_tv)
        TextView tvName;
        @BindView(R.id.item_shop_category_child_iv)
        RadiusImageView vImg;


        public ItemViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


}
